
/**
 * @class $$.date.Store
 * @extends Object
 */
$$.data.Store = function(cfg){
	Object.apply(this, cfg);
}
;(function(){
	$$.data.Store.prototype = {
		load: function(){
			this.reader.read("SELECT * FROM news");
		}
		
		/**
		 * 生成上一条记录，下一条记录功能
		 * @param {String} tableName 表名。
		 * @param {Number} opt opt有两个值，0或1.
		 * @return {String}
		 */
	    ,between : function(tableName, opt) {
			var 
				 html 	= '<a href="?ID={0}">{1}</a>'
				,ID 	= Number(Request.QueryString('ID')())
				,sql 	= opt
						? "SELECT ID, title FROM {0} WHERE ID < {1} ORDER BY ID DESC"
						: "SELECT ID, title FROM {0} WHERE ID > {1} ORDER BY ID"
				,sql 	= sql.format(tableName, ID);
	
			with (this.constructor(sql).rsObj) {
				html = EOF ? (opt ? "下面没有记录。" : "此为第一条记录。") : html.format(
						fields("ID").value, fields("title").value);
				Close();
			}
			return html;
		}
		// 计数器
		,readHits : function(table) {
			var 
				 sql	  = "UPDATE {0} SET ReadHits = ReadHits + 1 WHERE ID = {1}".format(table, Request('ID')())
				,sql	  = this.constructor(sql)
				,sql	  = "SELECT ReadHits FROM {0} WHERE ID = {1}".format(table, Request('ID')())
				,sql 	  = this.constructor(sql).rsObj
				,readHits = sql('readHits').value;
			
			sql.close();
			return readHits;
		}
	};
})();

/**
 * @class $$.date.Store
 * @extends $$.date.Store
 */
$$.data.XmlStore = function(cfg){
	Object.apply(this, cfg);
}
;(function(){
	
	/**
	 * @ not finish
	 * 从数据库导出XML格式
	 */
	$$.data.XmlStore.prototype.outputXML = function(){
	 	var ds = new DeepCMS.DataSaver();          
		ds.init();
		var rs = dp.getRS('a');
		var what = "xml";
		do{
			Response.Write('<'+what+'>');
			for(var i=0;i<(rs.Fields.Count);i++){
				if(rs.Fields(i).name+''=='remark_2'){
					Response.Write('<'+rs.Fields(i).name+'>');
					Response.Write("<![CDATA[" +rs.Fields(i).value+"]]>");
					Response.Write('</'+rs.Fields(i).name+'>');
				}else{
					Response.Write('<'+rs.Fields(i).name+'>');
					Response.Write(rs.Fields(i).value);
					Response.Write('</'+rs.Fields(i).name+'>');						
				}
			}
			Response.Write('</'+what+'>');
			rs.MoveNext();
		}while(!rs.EOF)
		Response.Write('<total>'+rs.RecordCount+'</total>');	 
	}
})();
Object.extend($$.data.Store, $$.data.XmlStore);
/**
 * @class $$.date.JsonStore
 * @extends $$.date.Store
 */
$$.data.JsonStore = function(cfg){
	Object.apply(this, cfg);
	debugger;
}
;(function(){

})();
Object.extend($$.data.Store, $$.data.JsonStore);